from django.contrib.auth import get_user_model
from backend.cews.models import StockItemGroup, TaskGroup
from rest_framework import serializers
from django.contrib.auth.models import Group, Permission
from backend.users.models import GroupSetting
from backend.eform.models import EformSchema

User = get_user_model()


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ["username", "staffNo", "url","name",'is_superuser']

        extra_kwargs = {
            "url": {"view_name": "api:user-detail", "lookup_field": "username"},
        }


class UserSearchSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ["id", "username", "email"]


class GroupSettingSerializer(serializers.ModelSerializer):
    username = serializers.ReadOnlyField()
    groupname = serializers.ReadOnlyField()

    class Meta:
        model = GroupSetting
        fields = '__all__'
        extra_fields = ['username','groupname']


class PermissionSerializer(serializers.ModelSerializer): 
    class Meta:
        model = Permission
        fields = '__all__'


class GroupSerializer(serializers.ModelSerializer): 
    class Meta:
        model = Group
        fields = '__all__'


class TaskGroupSerializer(serializers.ModelSerializer): 
    class Meta:
        model = TaskGroup
        fields = '__all__'


class StockItemGroupSerializer(serializers.ModelSerializer): 

     class Meta:
        model = StockItemGroup
        fields = '__all__'